package com.quasar.hpatient.receive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import lib.quasar.util.LogUtil;
import lib.quasar.util.ToastUtil;

/**
 * description: 安装完成和卸载完成监听
 * created by kalu on 2018/4/18 9:48
 */
public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //接收安装广播
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
            String packageName = intent.getDataString();
            ToastUtil.showToast("安装了:" + packageName + "包名的程序");
            LogUtil.e("BootReceiver", "安装了:" + packageName + "包名的程序");
        }
        //接收卸载广播
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {

//            Patient model = DBManager.getInstance().getPatientModel();
//            model.setCover(BaseConstant.NULL_STR);
//            model.setUserid(BaseConstant.NULL_STR);
//            DBManager.getInstance().updataPatientModel(model);

            String packageName = intent.getDataString();
            ToastUtil.showToast("卸载了:" + packageName + "包名的程序");
            LogUtil.e("BootReceiver", "卸载了:" + packageName + "包名的程序");
        }
        if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
            String packageName = intent.getDataString();
            ToastUtil.showToast("更新了:" + packageName + "包名的程序");
            LogUtil.e("BootReceiver", "更新了:" + packageName + "包名的程序");
        }
    }
}
